/**
 * Created by yuzhou on 2020/3/29.
 */
//获取
$(document).ready(function () {
    var app = new Vue({
        el: "#whole_box",
        data: {
            menu1:"",
            menu2:"",
            menu3:"",
            search_txt:"",

            category_list:[],
            store_list:[],

            is_en:false,

            language:"",

            current_category:"全部",
            current_category_id:0,
            current_market:"全部",
            current_market_id:"",

            market_option:"",
            category_txt:"",
            shop_no:"",
            main_pro_txt:"",

            market_item1:"",
            market_item2:"",
            market_item3:"",

            page_num:1,

            search_txt:""
        },
        mounted:function(){
            var self = this;
            self.language = localStorage.getItem("language");
            self.current_market_id = self.getQueryValue("market_type");
            var type_id = self.getQueryValue("id");

            if(self.language == "cn"){
                self.is_en = false;
                self.changeToCn();
                if( self.current_market_id == 999){
                    self.current_market = "全部";
                    self.requestStoreByCategory(type_id);
                }else if(self.current_market_id == 1){
                    self.current_market = "广州信基沙溪";
                    self.requestStoreByMarket();
                }else if(self.current_market_id == 2){
                    self.current_market = "广州信基豪泰";
                    self.requestStoreByMarket();
                }else if(self.current_market_id == 3){
                    self.current_market = "沈阳信基沙溪";
                    self.requestStoreByMarket();
                }
            }else{
                self.is_en = true;
                self.changeToEn();
                if( self.current_market_id == 999){
                    self.current_market = "All";
                    self.requestStoreByCategory(type_id);
                }else if(self.current_market_id == 1){
                    self.current_market = "XinjiShaxi(Guangzhou)";
                    self.requestStoreByMarket();
                }else if(self.current_market_id == 2){
                    self.current_market = "XinjiHotelex(Guangzhou)";
                    self.requestStoreByMarket();
                }else if(self.current_market_id == 3){
                    self.current_market = "XinjiShaxi(Shenyang)";
                    self.requestStoreByMarket();
                }
            }

            $(window).scroll(function () {
                var scrollTop = $(this).scrollTop();
                var scrollHeight = $(document).height();
                var windowHeight = $(this).height();

                if (Math.round(scrollTop + windowHeight) == scrollHeight) {
                    self.page_num += 11;
                    if(self.current_market_id == 999){
                        self.requestStoreByCategory( self.current_category_id);
                    }else{
                        self.requestStoreByCategoryAndMarket();
                    }
                }
            });


            $.ajax({
                type:"GET",
                url:"/market/getCategoryList",
                data: {
                    language:self.language
                },
                dataType:"json",
                success:function(res){
                    self.category_list = res;
                }
            });
        },
        methods: {
            getQueryValue:function (a) {
                var query = decodeURI(window.location.search.substring(1));
                var vars = query.split("&");
                for (var i = 0; i < vars.length; i++) {
                    var pair = vars[i].split("=");
                    if (pair[0] == a) { return pair[1]; }
                }
                return null;
            },

            getback:function () {
                window.history.back(-1);
            },

            changeToCn:function () {
                var self = this;
                self.search_txt = "搜索更多..";
                self.menu1 = "市场导购";
                self.menu2 = "动态资讯";
                self.menu3= "联系我们";
                self.market_item1 = "广州信基沙溪";
                self.market_item2 = "广州信基豪泰";
                self.market_item3 = "沈阳信基沙溪";
                self. market_option = "所属市场";
                self.category_txt = "所属品类";
                self.shop_no = "店铺号";
                self.main_pro_txt = "主营";
                self.search_txt="搜索更多..";
            },

            changeToEn:function () {
                var self = this;
                self.menu1 = "MarketShopping"+"\n"+"Guide";
                self.menu2 = "Dynamic"+"\n"+"Information";
                self.menu3 = "Contact Us";
                self.search_txt = "Search More..";
                self.market_item1 = "XinjiShaxi(Guangzhou)";
                self.market_item2 = "XinjiHotelex(Guangzhou)";
                self.market_item3 = "XinjiShaxi(Shenyang)";
                self. market_option = "Market";
                self.category_txt = "Category";
                self.shop_no = "Shop No";
                self.main_pro_txt = "Main Products";
                self.search_txt="Search More..";
            },

            chooseCatory:function (a,b) {
                var self = this;
                self.page_num = 1;
                self.current_category = b;
                self.current_category_id = a;
                if(self.current_market_id == 999){
                    self.requestStoreByCategory( self.current_category_id);
                }else{
                    self.requestStoreByCategoryAndMarket();
                }
            },

            chooseMarket:function (a,b) {
                var self = this;
                self.current_market = b;
                self.current_market_id = a;
                if(self.current_category_id == 0){
                    self.requestStoreByMarket();
                }else{
                    self.requestStoreByCategoryAndMarket();
                }
            },

            requestStoreByCategoryAndMarket:function () {
                var self = this;
                $.ajax({
                    type:"GET",
                    url:"/market/getStoreByType",
                    data: {
                        page:self.page_num,
                        type:self.current_category_id,
                        market_type:self.current_market_id,
                        language:self.language,
                    },
                    dataType:"json",
                    success:function(res){
                        if(self.page_num>1){
                            self.store_list = self.store_list.concat(res);
                        }else{
                            self.store_list = res;
                        }

                    }
                });
            },

            requestStoreByCategory:function (a) {
                var self = this;
                $.ajax({
                    type:"GET",
                    url:"/market/getAllStoreByType",
                    data: {
                        type:a,
                        language:self.language,
                        page:1
                    },
                    dataType:"json",
                    success:function(res){
                        if(self.page_num>1){
                            self.store_list = self.store_list .concat(res);
                        }else{
                            self.store_list = res;
                        }

                    }
                });
            },

            requestStoreByMarket:function () {
                var self = this;
                $.ajax({
                    type:"GET",
                    url:"/market/getMarketByTypeAll",
                    data: {
                        page:1,
                        type_id:self.current_market_id,
                        language:self.language
                    },
                    dataType:"json",
                    success:function(res){
                        self.store_list = res;
                    }
                });
            },

            storDetail:function (a) {
                window.location.href = "/page/redirectStoreDeatil?id="+a;
            },

            goSearch:function () {
                window.location.href="/page/redirectSearch";
            },

            callphone:function (a) {
                var self = this;
                window.location.href = "tel:"+a;
            }


        },

    });
});